<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@ include file="/WEB-INF/ibnms/common/jsCommonVariables.jsp"%>
	</head>
<body>
<div class="form-wrapper">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">用户管理</span>
             </h3>
        </div>
        <form name="theForm" >
			<input type="hidden" name="userForm.DEPT_ID" value="${userForm.DEPT_ID}"/>
		</form>
        <div class="box-in">
            <table border="0" cellspacing="0" cellpadding="0" class="table-03">
	            <tr>
		         	<td class="monitor_bg1" height="13" align ="right" nowrap>
		         		登录名：
			         	<input  type="text" class="input-style1" name="userForm.userId"/>
			     		姓名：
			         	<input  type="text" class="input-style1" name="userForm.userName"/>
			         	 <input type="button" class="btn-style02" id="btn-search" value="查询" />
			         </td>
		   		</tr>
            </table>
        </div>
        <div class="title-style"><a class="fold-tip"></a></div>
        <div class="block02">
      		<div class="title-style02">
                <input class="btn-style02" type="button" id="btn-add" value="增加">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-edit" value="修改">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-del" value="删除">
            </div>
            <table id="gridTable">
			</table>
			<div id="gridPager">
       	</div>
        </div>
</div>
</body>
		<script type="text/javascript">
			$(function(){
				$(".title-style a.fold-tip").toggle(toggletip,toggletip);
				function toggletip() {
					if ($(this).attr("class").split("unfold-tip").length > 1) {
						$(this).removeClass("unfold-tip");
						$(this).parents().prev(".box-in").show("fast");
					} else {
						$(this).addClass("unfold-tip");
						$(this).parents().prev(".box-in").hide("fast");
					}
				}
				$('#sel1').click(function(){
										  var height = $(window.parent.document.getElementById('sideframe')).height();
						$(window.parent.document.getElementById('sideframe')).css("display","none").next(".sideframe-collapse").css({"display":"block","height":height});
				})
			})

			$(function(){
				$("#gridTable").jqGrid({
					url: "loadListUserQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['登录名', '用户序列号', '姓名', '手机号', '固话号', '电子邮箱', '所在单位', '部门名称', '是否白名单','部门ID'],
                    colModel:[
						{name:'LOGIN_ID',index:'LOGIN_ID'},
						{name:'USER_ID',index:'USER_ID'},
						{name:'NAME',index:'NAME'},
						{name:'LOGIN_PHONE',index:'LOGIN_PHONE'},
						{name:'LOCAL_PHONE',index:'LOCAL_PHONE'},
						{name:'EMAIL_ADDR',index:'EMAIL_ADDR'},
						{name:'COMPANY_NAME',index:'COMPANY_NAME'},
						{name:'DEPT_NAME',index:'DEPT_NAME'},
						{name:'IS_VIP',index:'IS_VIP',formatter: function(value){
							if (value=="1"){
								return "是";
							} else {
								return "否";
							}
						}},
                        {name:'DEPT_ID',index:'DEPT_ID',hidden:true}
                    ],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true,
					beforeRequest:function(){
						var postData = {};
						$(":input[name^='userForm.']").each(function(){
							postData[$(this).attr("name")] = $(this).val();
						});
						$.extend($("#gridTable").getGridParam("postData"), postData);
					}
				});

			});


			$("#btn-search").click(function(){
				$("#gridTable").trigger("reloadGrid",[{page:1}]);
			});

			$("#btn-add").click(function(){
				$("form[name='theForm']").append("<input type='hidden' name='userForm.action_type' value='add'/>");
				$("form[name='theForm']").attr("action","<s:url action='editUserInfo' namespace='/'/>").submit();
			});
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }
				if(confirm("是否删除所选的记录?")){
					var LOGIN_ID = "";
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	LOGIN_ID += data.LOGIN_ID + ",";
                    }
                    if(LOGIN_ID.length>0){
                    	LOGIN_ID = LOGIN_ID.substring(0,LOGIN_ID.length-1);
                    }

					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="delUser" namespace='/'/>?userForm.LOGIN_ID="+LOGIN_ID,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       	}
						},
						error:function(xhr){
							show_error(xhr);
						}
					});
                }
			});
			$("#btn-edit").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择要修改的记录!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
						var LOGIN_ID = data.LOGIN_ID;
						$("form[name='theForm']").append("<input type='hidden' name='userForm.action_type' value='modify'/>");
						$("form[name='theForm']").append("<input type='hidden' name='userForm.LOGIN_ID' value='"+LOGIN_ID+"'/>");
						$("form[name='theForm']").attr("action","<s:url action='editUserInfo' namespace='/'/>");
                        $("input[name='userForm.DEPT_ID']").val(data.DEPT_ID);
                        $("form[name='theForm']").submit();
						break;
					default:
						alert("一次只能修改一条记录!");
				}
			});
		</script>
</html>            
